package cn.dnui_zjq823.dnuifood_16110100823.fragment;



import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import java.util.List;
import cn.dnui_zjq823.dnuifood_16110100823.R;
import cn.dnui_zjq823.dnuifood_16110100823.adapter.CShopAdapter;
import cn.dnui_zjq823.dnuifood_16110100823.adapter.FoodAdapter;
import cn.dnui_zjq823.dnuifood_16110100823.adapter.ShopAdapter;
import cn.dnui_zjq823.dnuifood_16110100823.bean.CollectionBean;
import cn.dnui_zjq823.dnuifood_16110100823.bean.ShopBean;
import cn.dnui_zjq823.dnuifood_16110100823.listener.onRetrofitListener;
import cn.dnui_zjq823.dnuifood_16110100823.model.CollectModel;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by dell on 2018/12/6.
 */

public class CollectionShopFragment extends BaseFragment implements onRetrofitListener {
    private RecyclerView recycler_cshop;
   private RecyclerView.LayoutManager layoutManager;
    private CShopAdapter shopAdapter;
    private List<CollectionBean> list;
    SharedPreferences sp;
    private int userid;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_collection_shop, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initRecycleview(view);
        sp=this.getActivity().getSharedPreferences("login",MODE_PRIVATE);
        String id=sp.getString("userid",null);
        userid=Integer.parseInt(id);
        CollectModel model=new CollectModel();
        model.getAllUserCollection(userid,0,this);
    }
    @Override
    public void onSuccess(Object object, int flag) {
        if (flag==0) {
            list = (List) object;
            shopAdapter = new CShopAdapter(context);
            shopAdapter.setList(list);
            recycler_cshop.setAdapter(shopAdapter);
        }
    }

    @Override
    public void onFalure(String msg) {
        Toast.makeText(context, "失败："+msg, Toast.LENGTH_SHORT).show();
    }

    private void initRecycleview(View view){
        recycler_cshop=view.findViewById(R.id.recycler_cshop);
        layoutManager=new LinearLayoutManager(context);
        recycler_cshop.setLayoutManager(layoutManager);
    }
}
